package io.github.betacatcode.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Account {
    private Long id;
    private String accountNumber;
    private BigDecimal available;

    /**
     * 转入
     */
    public void withdraw(BigDecimal money) {
        available = available.add(money);
    }

    /**
     * 转出
     */
    public void deposit(BigDecimal money) throws Exception {
        if (available.compareTo(money) == -1) {
            throw new Exception("转出账户没有足够余额");
        }
        available = available.subtract(money);
    }
}
